package com.yc.cloud.adminweb.controller;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.yc.cloud.adminweb.client.UserFeignClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class UserController {

	@Autowired
	private UserFeignClient userFeignClient;

	@HystrixCommand(fallbackMethod = "getErrorUser")//微服务调用出错时的回调函数
	@GetMapping("/user/{id}")
	public String findUserById(@PathVariable("id") Integer id){
		// return userService.findUserById(id);
		return userFeignClient.findById(id);
	}

	public String getErrorUser(Integer id){
		System.out.println("熔断，默认回调函数");
		return "{\"id\":-1,\"err\":\"熔断返回数据，服务不可用\"}";
	}


}
